﻿using System;
using System.Collections;
using System.Data;
using System.Data.OleDb;
using System.Data.SqlClient;
using System.Xml;
//using Microsoft.Win32;
using System.Linq;
using System.Data.Common;

using System.Collections.Generic;
using Aulac.Global.Enums; using Aulac.Global.Data; using Aulac.Global.Common; using Aulac.Global.Xml;
using Aulac.Rsc.Ems; using Aulac.Rsc.Ems.Tags;
using Aulac.Srv.Db.Data.Ems.Stores;
using Aulac.Srv.Db.Provider; using Aulac.Srv.Db.Connect;

namespace Aulac.Srv.Db.Data.Ems.Stores
{
	/// <summary>
	/// Quan ly mua hang, nhap kho, xuat kho noi bo
	/// </summary>
	public class StoreHelper 
	{
       
      public static string InnerJoinTable = string.Format(" FROM {0} h INNER JOIN {1} l ON h.{2} = l.{3}",
     TableNames.InvJrnHeader, TableNames.InvJrnLine, tagVch.Inv.InvJrnPrkID, tagVch.Inv.InvJrnPrkID);
       
     public static string CreateTableCacheUpdatePrimeCostForVch(Aulac.Srv.Db.Provider.IDbDataProvider pDbProvider, string pTableName)
        {
            string str = string.Format(" IF EXISTS (SELECT * from sysobjects   WHERE id = object_id(N'{0}') AND " +
                    " OBJECTPROPERTY(id, N'IsUserTable') = 1)  Delete From {1}", pTableName, pTableName);
            str += string.Format(" ELSE " +
                        " CREATE TABLE [dbo].[{0}] ( " +
                        " [{1}] [Decimal] NOT NULL , " +
                        " [{2}] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL " +
                        " ) ON [PRIMARY] ", pTableName, Aulac.Global.Xml.tagCtrl.VchID,
                        Aulac.Global.Xml.tagCtrl.VchTypeID);
            DbCommand cmd = pDbProvider.DbCommand;
            pDbProvider.ExecuteNonQuery(ref cmd, str);
            return pTableName;
        }

    }
}
